<template>
	<view class="content">
		<headerbox :cixitype="cixi"></headerbox>
		<view class="pages">
			<view class="card">
				<view class="card-body">
					<view class="display_space">
						<view class="label_title">索赔</view>
						<view class="btns" @click="goSwichPage('/pages/user/claimrecord')">查看索赔记录</view>
					</view>
					<view class="display_space">
						<view class="display_space" style="width: auto;">
							<image class="avatar" src="" mode=""></image>
							<view class="money">RMB</view>
						</view>
						<view class="right_package">
							<view class="inner_right_top">
								<view class="text1">您受MY保护</view>
								<image class="logo" src="../../static/logo.png" mode=""></image>
							</view>
							<view class="inner_right_bot" v-if="userinfos.is_claim != null">
								<image src="../../static/timg/cuowu.png" mode=""></image>
								<view>未受保护</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="card card1">
				<view class="card-body">
					<view class="d-flex">
						<image class="tishi" src="../../static/timg/tishi.png" mode=""></image>
						<view class="texts">请上传一个索赔附件，最多上传3个附件，格式为（PNG、JPEG或PDF每个文件不超过5MB）</view>
						<view class="close"></view>
					</view>
				</view>
			</view>
			<view class="card">
				<view class="card-body">
					<view class="attachment_header">
						<view class="title_date_wrap">
							<view class="titles">附件</view>
							<!-- <view class="date">今天日期: <text>{{userinfos.sj}}</text></view> -->
						</view>
					</view>
					<view class="inputbox">
						<view class="inputs" @click="uploadFilesFun()">
							<view class="insleft">选择文件</view>
							<view class="insright" v-if="fileItList.length==0">未选择任何文件</view>
							<view class="insright" v-if="fileItList.length>0">
								<span v-for="(it,index) in fileItList" :key="index">{{it}}</span>
							</view>
						</view>
					</view>
					<view class="fromitem">
						<view class="icon">
							<image src="../../static/timg/xing.png" mode=""></image>
						</view>
						<input class="input" type="password" placeholder="支付密码" v-model="zfpsd" />
						<view class="label">支付密码</view>
						<view class="right">必须</view>
					</view>
					<view class="buttons" @click="getbaoxianClaim">提交</view>
				</view>
			</view>
		</view>
		<view class="footer-bar" :class="cixi ? '':'footer-bar-detached'">
			<view class="fbitem" @click="goSwichPage('/pages/index/index')">
				<view class="image">
					<image src="../../static/timg/shouye.png" mode=""></image>
				</view>
				<view class="text">首页</view>
			</view>
			<view class="fbitem" @click="goSwichPage('/pages/contract/contract')">
				<view class="image">
					<image src="../../static/timg/heyue.png" mode=""></image>
				</view>
				<view class="text">合约</view>
			</view>
			<view class="fbitem" @click="goSwichPage('/pages/user/assets')">
				<view class="image">
					<image src="../../static/timg/zichan.png" mode=""></image>
				</view>
				<view class="text">资产</view>
			</view>
			<view class="fbitem" @click="goSwichPage('/pages/user/claim')">
				<view class="image">
					<image src="../../static/timg/suopei.png" mode=""></image>
				</view>
				<view class="text">索赔</view>
			</view>
		</view>
	</view>
</template>

<script>
	import headerbox from '@/pages/header.vue'
	import {
		baseURL
	} from '../../api/http.js'
	import {
		baoxianClaim,
		upload,
		getuserinfo
	} from '../../api/api.js'
	export default {
		components: {
			headerbox
		},
		data() {
			return {
				cixi: false,
				zfpsd: '',
				unfile: '',
				fileItList: [],
				userinfos:[]
			}
		},
		onLoad() {
			this.getuserinfofc()
			console.log(baseURL);
		},
		onPageScroll(e) {
			if (e.scrollTop > 0) {
				this.cixi = true
			} else {
				this.cixi = false
			}
		},
		methods: {
			getuserinfofc(){
				let datas = {
					type:1
				}
				getuserinfo(datas).then(res => {
					if(res.data.status.errorCode == 0){
						this.userinfos = res.data.data
					}
				}).catch(err => {
					console.log(err)
				})
			},
			goSwichPage(page) {
				uni.navigateTo({
					url: page
				})
			},
			// 上传文件
			uploadFilesFun() {
				let that = this;
				if (that.fileItList.length < 3) {
					uni.chooseFile({
						count: 1, //默认100
						extension: ['.png', '.jpeg', '.pdf', ],
						success: function(res) {
							uni.showToast({
								title: '加载中',
								icon: 'loading',
							});
							const tempFilePaths = res.tempFilePaths; //若果只选择一个文件,这个文件就是数组的第一个元素
							uni.uploadFile({
								url: baseURL + 'upload',
								filePath: tempFilePaths[0],
								success: (res) => {
									uni.hideLoading();
									console.log(JSON.parse(res.data))
									let uploadFile = JSON.parse(res.data).data.url
									console.log(uploadFile);
									that.fileItList.push(uploadFile)
								}
							})
						}
					})
				} else {
					uni.showToast({
						title: '最多上传三个',
						icon: 'none',
						duration: 2000
					});
				}
			},
			getbaoxianClaim() {
				if (!this.zfpsd) {
					uni.showToast({
						title: '请输入支付密码',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (this.fileItList.length == 0) {
					uni.showToast({
						title: '请上传附件',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				let datas = {
					qk_pwd: this.zfpsd,
					files: this.fileItList
				}
				baoxianClaim(datas).then(res => {
					if (res.data.status.errorCode == 0) {
						console.log(res.data);
						uni.showToast({
							title: res.data.status.msg,
							icon: 'success',
							duration: 2000
						});
						this.fileItList = [];
						this.zfpsd = '';
					} else {
						uni.showToast({
							title: res.data.status.msg,
							icon: 'error',
							duration: 2000
						});
					}
				}).catch(err => {
					console.log(err)
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	* {
		box-sizing: border-box;
	}

	.content {
		width: 100%;
		min-height: 100vh;
		background-color: #f1f1f7;
		color: #747474 !important;
	}

	.pages {
		padding-top: calc(calc(110rpx + 60rpx) + env(safe-area-inset-top));
		padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
	}

	.card {
		width: 94%;
		margin: 0 auto;
		border-radius: 20rpx;
		position: relative;
		display: flex;
		flex-direction: column;
		word-wrap: break-word;
		margin-bottom: 30rpx;
		background-color: #fff;
		box-shadow: rgba(0, 0, 0, .35) 0px 30px 60px -30px, rgba(0, 0, 0, .35) 0px -2px 6px 0px inset;
	}

	.card1 {
		background-color: rgba(74, 137, 220, 0.25) !important;
	}

	.card-body {
		z-index: 3;
		flex: 1 1 auto;
		padding: 40rpx;
	}

	.display_space {
		font-size: 26rpx;
		font-weight: bold;
		color: #2a2a2a;
		margin-bottom: 4rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.label_title {
		font-size: 28rpx;
		font-weight: bold;
	}

	.btns {
		font-size: 22rpx;
		padding: 16rpx 26rpx;
		font-weight: 700;
		border-radius: 24rpx;
		box-shadow: 0 5px 14px 0 rgba(0, 0, 0, 0.1);
		background-image: linear-gradient(to bottom, #5D9CEC, #4A89DC) !important;
		color: #FFF !important;
		line-height: 1.5;
	}

	.avatar {
		width: 120rpx;
		height: 120rpx;
		margin: 0 20rpx 0 0;
	}

	.money {
		font-size: 32rpx;
		line-height: 52rpx;
	}

	.right_package {
		width: 45%;
		text-align: right;
		font-size: 26rpx;
		font-weight: bold;
		color: #2a2a2a;
		margin-bottom: 4rpx;
	}

	.inner_right_top {
		display: flex;
		align-items: center;
		padding-bottom: 32rpx;
		justify-content: flex-end;
	}

	.text1 {
		width: 84rpx;
		font-size: 20rpx;
		line-height: 1.2;
		padding-right: 12rpx;
		padding-left: 20rpx;
	}

	.logo {
		width: 190rpx;
		height: 134rpx;
		padding: 8rpx;
	}

	.inner_right_bot {
		height: 50rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;

		image {
			width: 24rpx;
			height: 24rpx;
			margin-right: 4rpx;
		}

		view {
			color: #f00;
			font-size: 24rpx;
			font-weight: normal;
		}
	}

	.d-flex {
		display: flex;
		align-items: center;
	}

	.tishi {
		width: 66rpx;
		height: 66rpx;
	}

	.texts {
		flex: 1;
		font-size: 28rpx;
		line-height: 36rpx;
		color: #4A89DC !important;
		padding-left: 40rpx;
		padding-right: 20rpx;
	}

	.close {
		width: 22rpx;
		height: 22rpx;
		background: transparent url('../../static/timg/guanbi.svg') center / 22rpx auto no-repeat;
		opacity: 0.2 !important;
	}

	.attachment_header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0px 0 20rpx;
	}

	.titles {
		color: #c5993a;
		font-size: 32rpx;
		line-height: 44rpx;
		font-weight: bold;
	}

	.date {
		padding-top: 6rpx;
		font-size: 24rpx;
		color: #c5993a;
		line-height: 48rpx;

		text {
			font-weight: bold;
		}
	}

	.inputbox {
		padding: 20rpx;
		margin-bottom: 40rpx;
	}

	.inputs {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 70rpx;
		border: 2rpx solid #ced4da;
		border-radius: 20rpx;
		color: #212529;
		font-size: 24rpx;
		overflow: hidden;

		.insleft {
			width: 30%;
			height: 66rpx;
			text-align: center;
			line-height: 66rpx;
			background-color: #ced4da;
		}

		.insright {
			width: 70%;
			overflow: hidden;
			height: 66rpx;
			line-height: 66rpx;
			background-color: #fff;
			padding-left: 20rpx;
		}
	}

	.fromitem {
		position: relative;
		margin-bottom: 40rpx;

		.right {
			position: absolute;
			top: 0px;
			right: 20rpx;
			height: 106rpx;
			line-height: 106rpx;
			pointer-events: none;
			font-size: 20rpx;
			opacity: 0.5;
			color: #747474 !important;
		}
	}

	.icon {
		position: absolute;
		width: 80rpx;
		height: 106rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.icon image {
		width: 28rpx;
		height: 28rpx;
	}

	.fromitem .input {
		width: 100%;
		height: 106rpx;
		line-height: 102rpx;
		border: 2rpx solid rgba(0, 0, 0, 0.07) !important;
		padding-left: 80rpx;
		padding-right: 30rpx;
		border-radius: 20rpx;
		font-size: 24rpx;
		outline: 0;
		color: #000;
	}

	.label {
		position: absolute;
		top: -10rpx;
		height: 20rpx;
		line-height: 20rpx;
		left: 0;
		font-size: 22rpx;
		text-transform: uppercase;
		font-family: "Nunito", sans-serif;
		font-weight: 700;
		transition: all 250ms ease;
		padding-left: 2px !important;
		padding-right: 5px !important;
		color: #0f1117;
		transform: translateX(80rpx) !important;
		margin-left: -64rpx !important;
	}

	.buttons {
		width: 100%;
		text-align: center;
		font-size: 24rpx;
		font-weight: 700 !important;
		padding: 24rpx 36rpx;
		box-shadow: 0 10rpx 28rpx 0 rgba(0, 0, 0, 0.1);
		background-color: #4A89DC !important;
		color: #FFF !important;
		border-radius: 20rpx !important;
		margin-top: 60rpx;
	}

	.footer-bar {
		background-color: rgba(255, 255, 255, 0.95);
		padding: 0px 20rpx;
		position: fixed;
		bottom: 0px;
		left: 0px;
		right: 0px;
		z-index: 98;
		backdrop-filter: blur(20rpx);
		display: flex;
		text-align: center;
		transition: all 250ms ease;
		height: calc(120rpx + env(safe-area-inset-bottom));
		box-shadow: 0 -10rpx 10rpx 0 rgba(0, 0, 0, 0.04);
	}

	.footer-bar.footer-bar-detached {
		border-radius: 40rpx;
		left: 20rpx !important;
		right: 20rpx !important;
		bottom: 30rpx !important;
		box-shadow: 0 0px 30rpx 0 rgba(0, 0, 0, 0.1) !important;
		height: 120rpx !important;
	}

	.fbitem {
		color: #818181;
		position: relative;
		flex: 1 1 auto;
		padding-top: 24rpx;

		.image {
			height: 48rpx;
			margin-top: -4rpx;

			image {
				width: 36rpx;
				height: 36rpx;
			}
		}

		.text {
			height: 48rpx;
			margin-top: -6rpx;
			font-size: 24rpx;
			opacity: 0.7;
			color: #818181;
		}
	}
</style>